title: Dialog (Python) description: Python-side synchronous Dialog API: alert / confirm / prompt / actionSheet wrappers around the host's modal UI.


The scripting Python package exposes Dialog, mirroring the JS-side Dialog namespace. It provides synchronous wrappers around the host's modal UI — alerts, confirms, prompts and action sheets. Each call blocks until the user dismisses the dialog and returns the result.

import scripting; Dialog = scripting.Dialog

The dialog is displayed on top of the currently visible view controller, so this only makes sense when the host app is in the foreground (e.g. when the user explicitly ran the script from the app).


Methods

Dialog.alert(message, title=None, buttonLabel=None) -> None

Show a single-button alert. Returns when the user taps the dismiss button.

import scripting; Dialog = scripting.Dialog
Dialog.alert("Operation completed", title="Done")
ParamTypeRequiredDescription
messagestrYesBody text of the alert.
titlestrNoOptional title above the message.
buttonLabelstrNoCustom dismiss button label. Defaults to localized OK.

Dialog.confirm(message, title=None, cancelLabel=None, confirmLabel=None) -> bool

Show a two-button confirm dialog. Returns True when the user taps the confirm button, False for cancel.

import scripting; Dialog = scripting.Dialog

if Dialog.confirm("Delete the file?", title="Confirm",
                  cancelLabel="Keep", confirmLabel="Delete"):
    delete_file()
ParamTypeRequiredDescription
messagestrYesBody text.
titlestrNoTitle.
cancelLabelstrNoCustom cancel button label.
confirmLabelstrNoCustom confirm button label.

Dialog.prompt(title=None, message=None, defaultValue=None, placeholder=None, obscureText=False, cancelLabel=None, confirmLabel=None) -> str | None

Show a text-input prompt. Returns the entered string, or None if the user cancelled.

import scripting; Dialog = scripting.Dialog

name = Dialog.prompt(title="Your name", placeholder="Alice")
if name is not None:
    print(f"Hello, {name}")
ParamTypeRequiredDescription
titlestrNoTitle.
messagestrNoOptional supporting text below the title.
defaultValuestrNoPre-filled text in the input.
placeholderstrNoPlaceholder shown when the input is empty.
obscureTextboolNoWhen True, masks the input (password style). Defaults to False.
cancelLabelstrNoCustom cancel button label.
confirmLabelstrNoCustom confirm button label.

Dialog.actionSheet(title, actions, message=None, cancelButton=True) -> int | None

Show an action sheet with multiple choices. Returns the index of the chosen action (0-based), or None if cancelled.

import scripting; Dialog = scripting.Dialog

idx = Dialog.actionSheet(
    title="Choose an export format",
    actions=[
        {"label": "JSON"},
        {"label": "CSV"},
        {"label": "Delete original", "destructive": True},
    ],
)
if idx == 0:
    export_json()
elif idx == 1:
    export_csv()
elif idx == 2:
    delete_original()
ParamTypeRequiredDescription
titlestrYesSheet title.
actionslist[dict]YesList of {"label": str, "destructive": bool?}. destructive=True renders the action in red.
messagestrNoOptional supporting text.
cancelButtonboolNoShow a cancel button (defaults to True).